﻿using System;
using System.Globalization;
using System.Windows.Data;
using Microsoft.TeamFoundation.WorkItemTracking.Client;

namespace TaskCardReport.Converters
{
  class ParentIdConverter : IValueConverter
  {
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
      var workItem = value as WorkItem;
      foreach (var link in workItem.Links)
      {
        var relatedLink = link as RelatedLink;
        if (relatedLink != null)
        {
          if (relatedLink.LinkTypeEnd.Name == "Parent")
            return relatedLink.RelatedWorkItemId.ToString();
        }
      }
      return "-";
    }

    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    {
      throw new NotImplementedException();
    }
  }
}